# encoding: utf-8

class ImageUploader < CarrierWave::Uploader::Base

  include CarrierWave::MiniMagick
  include CarrierWave::MimeTypes

  storage :file

  def store_dir
    date = "#{model.created_at.year}-#{model.created_at.month}-#{model.created_at.day}"
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{date}"
  end

  version :thumb do
    process :resize_to_fit => [100, 100]
  end

  def extension_white_list
    %w(jpg jpeg gif png)
  end

  def filename
    if super.present?
      @name ||= "#{SecureRandom.uuid}.#{file.extension.downcase}"
    end
  end

end
